package model

import (
	"jiance_server/mongo"

	mgo "gopkg.in/mgo.v2"
)

type Notice struct {
	ID         string `bson:"_id,omitempty" json:"id"`
	Title      string `bson:"Title" json:"title"`
	CreateTime int64  `bson:"CreateTime" json:"createTime"`
	Link       string `bson:"Link" json:"link"`
	Content    string `bson:"Content,omitempty" json:"content,omitempty"`
}

func ListNotice(pageIndex int, pageSize int, selector interface{}) (notices []Notice, err error) {
	return notices, mongo.Notice.WithC(func(c *mgo.Collection) error {
		return c.Find(nil).Select(selector).Skip(pageIndex * pageSize).Limit(pageSize).All(&notices)
	})
}

func FindNoticeByID(id string, selector interface{}) (notice *Notice, err error) {
	notice = &Notice{}
	return notice, mongo.Notice.WithC(func(c *mgo.Collection) error {
		return c.FindId(id).Select(selector).One(notice)
	})
}
